package cqcvc.edu.cn.servlet;

import cqcvc.edu.cn.dao.HouseDao;
import cqcvc.edu.cn.entity.HouseInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

//houseShowPic
@WebServlet(name = "HouseImageShowServlet",urlPatterns = "/images/houseShowPic")
public class HouseImageShowServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HouseDao houseDao=new HouseDao();
        Long id=Long.parseLong(request.getParameter("id"));
        HouseInfo houseInfo=houseDao.findById(id);
        byte[] img=houseInfo.getHousePic();
        if(img!=null)
        {
            OutputStream outputStream=response.getOutputStream();
            outputStream.write(img);
            outputStream.flush();
            outputStream.close();
        }
    }
}
